//logs.js
const util = require('../../utils/util.js')
import request from "../../utils/request";
var api = require("../../utils/api");

Page({
  data: {
    cellData: [],
    tabId: '',
    stateArr: [
      {
        name: '',
        className: '',
        textClass:''
      }, {
        name: '待处理',
        className: 'back-blue',
        textClass: 'blue'
      },
      {
        name: '处理中',
        className: 'back-green',
        textClass: 'green'
      },
      {
        name: '已处理',
        className: 'back-yellow',
        textClass: 'yellow'
      },
      {
        name: '处理中',
        className: 'back-green',
        textClass: 'green'
      },{
        name: '已处理',
        className: 'back-red',
        textClass: 'red'
      },{
        name: '已奖励',
        className: 'back-red',
        textClass: 'red'
      }
    ],
    noData: false
  },

  onLoad() {
    this.fetchData()
  },
  onTab(e){
    var tabId = e.currentTarget.dataset.tabid
    this.setData({
      tabId: Number(tabId)
    })
    this.fetchData()
  },
  fetchData() {
    var url = api.Secrethistory
    var params = {
      list_rows: 100,
      page: 1,
      check_status: this.data.tabId
    }
    if(this.data.tabId === 2){
      params.check_status = '2,4'
    }else if(this.data.tabId === 3){
      params.check_status = '3,5'
    }
    request(url, params, "POST").then(res => {
       
      if (res.code == 0) {
        var result = res.data.data;
        if(result.length === 0){
          this.setData({
            noData: true
          })
        }else{
          result.forEach(item => {
            item.content = util.escape2Html(item.content)
          })
          this.setData({
            cellData: result,
            noData: false
          })
        }
      }
    })
  }
})